package com.h3bpm.kumhosunny.review.controller;

import OThinker.Common.Organization.Models.User;
import OThinker.H3.Controller.ControllerBase;
import OThinker.H3.Entity.DataModel.BizObject;
import OThinker.H3.Entity.Instance.Data.InstanceData;
import com.alibaba.fastjson.JSONObject;
import com.h3bpm.kumhosunny.common.utils.SqlUtil;
import com.h3bpm.kumhosunny.review.entity.TempProject;
import com.h3bpm.kumhosunny.review.entity.TempProjectSpeed;
import data.DataRow;
import data.DataTable;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestParam;
import org.springframework.web.bind.annotation.ResponseBody;

import javax.servlet.http.HttpServletRequest;
import java.text.SimpleDateFormat;
import java.util.*;

@Controller
@RequestMapping(value = "/Portal/Review")
public class ReviewController extends ControllerBase {


    @Override
    public String getFunctionCode() {
        return null;
    }

    @RequestMapping(value = "/NonView.html")
    public String ReviewDataIndex(HttpServletRequest request) throws Exception {
        SimpleDateFormat simpleDateFormat = new SimpleDateFormat("yyyy-MM-dd HH:mm:ss");
        DataTable dataTable = SqlUtil.doQuery("SELECT * FROM i_projectinit ip GROUP BY ip.projectNumber ORDER BY ip.RunningInstanceId");
        List<DataRow> dataRows = dataTable.getEntityRows();

        //临时项目对象
        List<TempProject> tempProjects = new ArrayList<TempProject>();

        if (!dataRows.isEmpty()) {

            //遍历赋值
            for (DataRow dataRow : dataRows) {
                String projectName = dataRow.getString("projectname");
                String projectNumber = dataRow.getString("projectnumber");
                //数据放入list
                TempProject tempProject = new TempProject();
                tempProject.setObjectID(dataRow.getString("objectid"));

                tempProject.setProjectName(projectName);
                tempProject.setProjectNumber(projectNumber);
                tempProject.setProjectType(dataRow.getString("projecttype"));
                tempProject.setInBudget(dataRow.getString("inbudget"));

                //当前发起用户
                // User user = (User) getEngine().getOrganization().GetUnit(dataRow.getString("createdby"));
                String userName = SqlUtil.doQuery("SELECT `Name` FROM ot_user WHERE ObjectID='" + dataRow.getString("createdby") + "'").getRows().get(0).getString(0);
                tempProject.setCreatedBy(userName);
                //组织名称
                tempProject.setParentPropertyName(getEngine().getOrganization().GetUnit(SqlUtil.doQuery("SELECT `ParentID` FROM ot_user WHERE ObjectID='" + dataRow.getString("createdby") + "'").getRows().get(0).getString(0)).getName());
                tempProject.setCreatedTime(simpleDateFormat.parse(dataRow.getString("createdtime")));

                //流程结束时间
                String instanceId = dataRow.getString("runninginstanceid");

                if (instanceId.isEmpty()) {
                    //从流程主表查
                    DataTable instanData = SqlUtil.doQuery("SELECT * FROM ot_instancecontext WHERE BizObjectId='" + dataRow.getString("objectid") + "'");
                    if (instanData.getRows().size() != 0) {
                        instanceId = instanData.getRows().get(0).getString(0);
                    }

                }
                if (!instanceId.isEmpty()) {
                    tempProject.setRunningInstanceId(instanceId);
                    try {
                        DataTable instanceDataTable = new DataTable();
                        instanceDataTable = SqlUtil.doQuery("SELECT * FROM ot_instancecontext WHERE BizObjectId='" + dataRow.getString("objectid") + "'");
                        Date projectEndTime = instanceDataTable.getRows().get(0).getDateTime("estimatedfinishtime");
                        tempProject.setModifiedTime(projectEndTime);

                        InstanceData instanceData = new InstanceData(getEngine(), instanceId, User.AdministratorID);
                        //数据封装
                        HashMap<String, Object> datas = instanceData.getBizObject().getValueTable();

                        //项目组长
                        String[] leaderArray = null;
                        leaderArray = (String[]) datas.get("projectLeader");
                        if (null != leaderArray && leaderArray.length != 0) {
                            //项目组长id
                            String objectid=leaderArray[0];
                            String leaderName = SqlUtil.doQuery("SELECT `Name` FROM ot_user WHERE ObjectID='" + objectid + "'").getRows().get(0).getString(0);
                            tempProject.setProjectLeader(leaderName);
                        }
                    } catch (Exception e) {

                    }


                    //各个阶段用时计算
                    DataTable projectDataTable = SqlUtil.doQuery("SELECT * FROM i_projectinit ip WHERE ip.projectNumber='" + projectNumber + "'");
                    DataRow projectDataRow = dataTable.getRows().get(0);
                    if (null != dataRow) {
                        while (true) {
                            //一个不满足跳出
                            //方案评估
                            DataTable schemeTable = new DataTable();
                            schemeTable = SqlUtil.doQuery("SELECT * FROM i_schemeevaluation WHERE projectNumber='" + projectNumber + "'");

                            if(schemeTable.getRows()!=null && schemeTable.getRows().size()>0){
                                //计算方案评估用时
                                Date schemeCreatedDate = schemeTable.getRows().get(0).getDate("createdtime");
                                Date initCreatedDate = dataTable.getRows().get(0).getDate("createdtime");
                                tempProject.setProjectUseNeedDate(getDatePoor(schemeCreatedDate, initCreatedDate));
                            }

                            //合同评审数据
                            DataTable contractTable = new DataTable();
                            contractTable = SqlUtil.doQuery("SELECT * FROM i_contractreview WHERE projectNumber='" + projectNumber + "'");

                            if(schemeTable.getRows()!=null && schemeTable.getRows().size()>0 && contractTable.getRows()!=null && contractTable.getRows().size()>0){
                                Date contractCreatedDate = contractTable.getRows().get(0).getDate("createdtime");
                                tempProject.setProjectUseAssessDate(getDatePoor(contractCreatedDate, schemeTable.getRows().get(0).getDate("createdtime")));
                            }

                            //验收方案制定申请单数据
                            DataTable acceptanceTable = new DataTable();
                            acceptanceTable = SqlUtil.doQuery("SELECT * FROM i_acceptancestandardapp WHERE projectNumber='" + projectNumber + "'");

                            if(acceptanceTable.getRows()!=null && acceptanceTable.getRows().size()>0 && contractTable.getRows()!=null && contractTable.getRows().size()>0){
                                Date acceptanceCreatedDate = acceptanceTable.getRows().get(0).getDate("createdtime");
                                tempProject.setProjectUseCheckDate(getDatePoor(acceptanceCreatedDate, contractTable.getRows().get(0).getDate("createdtime")));
                            }

                            //项目总结
                            DataTable totalNoticeTable = new DataTable();
                            totalNoticeTable = SqlUtil.doQuery("SELECT * FROM i_acceptancesummarynotice WHERE projectNumber='" + projectNumber + "'");


                            //验收实施
                            DataTable implementTable = new DataTable();
                            implementTable = SqlUtil.doQuery("SELECT * FROM i_implementationcheck WHERE projectNumber='" + projectNumber + "'");

                            if(implementTable.getRows()!=null && implementTable.getRows().size()>0 && totalNoticeTable.getRows()!=null && totalNoticeTable.getRows().size()>0){
                                Date checkUseCreatedDate = implementTable.getRows().get(0).getDate("createdtime");
                                Date projectTotalCreatedDate = totalNoticeTable.getRows().get(0).getDate("createdtime");
                                tempProject.setProjectUseTotalDate(getDatePoor(projectTotalCreatedDate, checkUseCreatedDate));
                            }
                            break;
                        }

                    }

                }
                tempProjects.add(tempProject);
            }
        }
        request.setAttribute("projects", tempProjects);

        return "/Portal/NonDataView.jsp";
    }

    @RequestMapping(value = "/findRelatedPerson")
    @ResponseBody
    public String ajaxGetRelatedPerson(@RequestParam("objectid") String objectId) throws Exception {
        DataTable dataTable = SqlUtil.doQuery("SELECT * FROM ot_instancecontext WHERE BizObjectId='" + objectId + "'");
        DataRow dataRow = dataTable.getRows().get(0);
        TempProject tempProject = new TempProject();
        String instanceId = dataRow.getString("objectid");


        if (!instanceId.isEmpty()) {
            try {
                InstanceData instanceData = new InstanceData(getEngine(), instanceId, User.AdministratorID);
                //数据封装
                HashMap<String, Object> datas = instanceData.getBizObject().getValueTable();

                //项目组长
                String[] leaderArray = null;
                leaderArray = (String[]) datas.get("projectLeader");
                if (null != leaderArray && leaderArray.length != 0) {
                    String tempPerson = "";
                    for (int i = 0; i < leaderArray.length; i++) {
                        tempPerson += getEngine().getOrganization().GetUnit(leaderArray[i])._Name + ",";
                    }
                    tempProject.setProjectLeader(tempPerson);
                }

                //技术评审负责人
                String[] technologyArray = new String[0];
                technologyArray = (String[]) datas.get("technologyLeader");
                if (null != technologyArray && technologyArray.length != 0) {
                    String tempPerson = "";
                    for (int i = 0; i < technologyArray.length; i++) {
                        tempPerson += getEngine().getOrganization().GetUnit(technologyArray[i])._Name + ",";
                    }
                    tempProject.setTechnologyLeader(tempPerson);
                }

                //技术评审组员
                String[] technouserArray = new String[0];
                technouserArray = (String[]) datas.get("technologyMember");
                if (null != technouserArray && technouserArray.length != 0) {
                    String tempPerson = "";
                    for (int i = 0; i < technouserArray.length; i++) {
                        tempPerson += getEngine().getOrganization().GetUnit(technouserArray[i])._Name + ",";
                    }
                    tempProject.setTechnologyMember(tempPerson);
                }

                //商务评审负责人
                String[] businessArray = new String[0];
                businessArray = (String[]) datas.get("businessLeader");
                if (null != businessArray && businessArray.length != 0) {
                    String tempPerson = "";
                    for (int i = 0; i < businessArray.length; i++) {
                        tempPerson += getEngine().getOrganization().GetUnit(businessArray[i])._Name + ",";
                    }
                    tempProject.setBusinessLeader(tempPerson);
                }

                //商务评审组员
                String[] businessuserArray = new String[0];
                businessuserArray = (String[]) datas.get("businessMember");
                if (null != businessuserArray && businessuserArray.length != 0) {
                    String tempPerson = "";
                    for (int i = 0; i < businessuserArray.length; i++) {
                        tempPerson += getEngine().getOrganization().GetUnit(businessuserArray[i])._Name + ",";
                    }
                    tempProject.setBusinessMember(tempPerson);
                }

                //运管委委员
                String[] operationArray = new String[0];
                operationArray = (String[]) datas.get("operationManager");
                if (null != operationArray && operationArray.length != 0) {
                    String tempPerson = "";
                    for (int i = 0; i < operationArray.length; i++) {
                        tempPerson += getEngine().getOrganization().GetUnit(operationArray[i])._Name + ",";
                    }
                    tempProject.setOperationManager(tempPerson);
                }


            } catch (Exception e) {
                System.out.println(e);
            }

        }

        return JSONObject.toJSONString(tempProject);
    }

    @RequestMapping(value = "/findRunningData")
    @ResponseBody
    public String ajaxGetRunningData(@RequestParam("projectNumber") String projectNumber) throws Exception {
        DataTable dataTable = SqlUtil.doQuery("SELECT * FROM i_projectinit ip WHERE ip.projectNumber='" + projectNumber + "'");
        SimpleDateFormat simpleDateFormat = new SimpleDateFormat("yyyy-MM-dd HH:mm:ss");
        DataRow dataRow = dataTable.getRows().get(0);
        //存储总流程进度以及相关数据
        List<TempProjectSpeed> tempProjectSpeeds = new ArrayList<TempProjectSpeed>();

        if (null != dataRow) {
            while (true) {
                //一个不满足跳出
                DataTable schemeTable = new DataTable();
                schemeTable = SqlUtil.doQuery("SELECT * FROM i_schemeevaluation WHERE projectNumber='" + projectNumber + "'");
                if (schemeTable.getRows() != null && schemeTable.getRows().size() > 0) {
                    TempProjectSpeed tempProjectSpeed = new TempProjectSpeed();
                    //进度增加
                    tempProjectSpeed.setNowProgreProjectName("方案评估");
                    tempProjectSpeed.setNowState(true);
                    tempProjectSpeed.setSort(tempProjectSpeed.getSort() + 1);

                    //封装数据
                    HashMap<String, Object> datas = new HashMap<>();
                    datas.put("createTime", schemeTable.getRows().get(0).getString("createdtime"));
                    tempProjectSpeed.setDatas(datas);
                    tempProjectSpeeds.add(tempProjectSpeed);
                } else {
                    //break;
                }

                //合同评审数据
                DataTable contractTable = new DataTable();
                contractTable = SqlUtil.doQuery("SELECT * FROM i_contractreview WHERE projectNumber='" + projectNumber + "'");
                if (contractTable.getRows() != null && contractTable.getRows().size() > 0) {
                    TempProjectSpeed tempProjectSpeed = new TempProjectSpeed();
                    tempProjectSpeed.setNowProgreProjectName("合同评审");
                    tempProjectSpeed.setNowState(true);
                    tempProjectSpeed.setSort(tempProjectSpeed.getSort() + 1);
                    //封装数据
                    HashMap<String, Object> datas = new HashMap<>();
                    datas.put("createTime", contractTable.getRows().get(0).getString("createdtime"));
                    tempProjectSpeed.setDatas(datas);
                    tempProjectSpeeds.add(tempProjectSpeed);
                } else {
                    //break;
                }

                //验收方案制定申请单数据
                DataTable acceptanceTable = new DataTable();
                acceptanceTable = SqlUtil.doQuery("SELECT * FROM i_acceptancestandardapp WHERE projectNumber='" + projectNumber + "'");
                if (acceptanceTable.getRows() != null && acceptanceTable.getRows().size() > 0) {
                    TempProjectSpeed tempProjectSpeed = new TempProjectSpeed();
                    tempProjectSpeed.setNowProgreProjectName("验收方案定制");
                    tempProjectSpeed.setNowState(true);
                    tempProjectSpeed.setSort(tempProjectSpeed.getSort() + 1);

                    //封装数据
                    HashMap<String, Object> datas = new HashMap<>();

                    //根据objectid获取instancecontext数据
                    DataTable instanceDataTable = new DataTable();
                    instanceDataTable = SqlUtil.doQuery("SELECT * FROM ot_instancecontext WHERE BizObjectId='" + acceptanceTable.getRows().get(0).getString("objectid") + "'");

                    if (instanceDataTable.getRows() != null && acceptanceTable.getRows().size() > 0) {
                        //获取引擎数据
                        InstanceData instanceData = new InstanceData(getEngine(), instanceDataTable.getRows().get(0).getString("objectid"), User.AdministratorID);
                        //获取子表数据验收负责人
                        HashMap<String, Object> maps = instanceData.getBizObject().getValueTable();
                        BizObject[] bizObjects = (BizObject[]) maps.get("inspectionIncomingMerchandise");
                        //遍历获取验收负责人
                        String checkDreftPerson = "";
                        String checkPerson = "";
                        for (BizObject bizObject : bizObjects) {
                            String userObjectId = (String) bizObject.getValueTable().get("acceptanceLeader");

                            if (userObjectId != null && !"".equals(userObjectId)) {
                                checkPerson += getEngine().getOrganization().GetUnit(userObjectId).getName() + ",";
                            }


                            String dreftObjectId = (String) bizObject.getValueTable().get("nominator");

                            if (dreftObjectId != null && !"".equals(dreftObjectId)) {
                                checkDreftPerson += getEngine().getOrganization().GetUnit(dreftObjectId).getName() + ",";
                            }

                        }
                        //放入返回数据Map
                        datas.put("checkPerson", checkPerson);
                        datas.put("checkDreftPerson", checkDreftPerson);
                        //遍历获取使用负责人
                        BizObject[] inspectionBizObjects = (BizObject[]) maps.get("usingAcceptance");
                        String usingDreftPerson = "";
                        String usingPerson = "";
                        for (BizObject bizObject : inspectionBizObjects) {
                            String userObjectId = (String) bizObject.getValueTable().get("acceptanceLeader");

                            if (userObjectId != null && !"".equals(userObjectId)) {
                                usingPerson += getEngine().getOrganization().GetUnit(userObjectId).getName() + ",";
                            }

                            String dreftObjectId = (String) bizObject.getValueTable().get("nominator");

                            if (dreftObjectId != null && !"".equals(dreftObjectId)) {
                                usingDreftPerson += getEngine().getOrganization().GetUnit(dreftObjectId).getName() + ",";
                            }

                        }
                        //放入返回数据Map
                        datas.put("usingPerson", usingPerson);
                        datas.put("usingDreftPerson", usingDreftPerson);

                        //获取项目最后结束时间
                        String endTime = instanceDataTable.getRows().get(0).getString("estimatedfinishtime");
                        if (null != endTime) {
                            datas.put("endTime", endTime);
                        }
                    }

                    datas.put("createTime", acceptanceTable.getRows().get(0).getString("createdtime"));

                    //获取发起人
                    User user = (User) getEngine().getOrganization().GetUnit(acceptanceTable.getRows().get(0).getString("createdby"));
                    datas.put("createUser", user.getFullName());


                    tempProjectSpeed.setDatas(datas);
                    tempProjectSpeeds.add(tempProjectSpeed);
                } else {
                    //break;
                }

                //验收实施
                DataTable implementTable = new DataTable();
                implementTable = SqlUtil.doQuery("SELECT * FROM i_implementationcheck WHERE projectNumber='" + projectNumber + "'");
                if (implementTable.getRows() != null && implementTable.getRows().size() > 0) {
                    TempProjectSpeed tempProjectSpeed = new TempProjectSpeed();
                    tempProjectSpeed.setNowProgreProjectName("验收实施");
                    tempProjectSpeed.setNowState(true);
                    tempProjectSpeed.setSort(tempProjectSpeed.getSort() + 1);
                    //封装数据
                    HashMap<String, Object> datas = new HashMap<>();
                    datas.put("createTime", implementTable.getRows().get(0).getString("createdtime"));
                    tempProjectSpeed.setDatas(datas);
                    tempProjectSpeeds.add(tempProjectSpeed);
                } else {
                    //break;
                }

                //项目总结
                DataTable totalNoticeTable = new DataTable();
                totalNoticeTable = SqlUtil.doQuery("SELECT * FROM i_acceptancesummarynotice WHERE projectNumber='" + projectNumber + "'");
                if (totalNoticeTable.getRows() != null && totalNoticeTable.getRows().size() > 0) {
                    TempProjectSpeed tempProjectSpeed = new TempProjectSpeed();
                    tempProjectSpeed.setNowProgreProjectName("项目总结");
                    tempProjectSpeed.setNowState(true);
                    tempProjectSpeed.setSort(tempProjectSpeed.getSort() + 1);
                    //封装数据
                    HashMap<String, Object> datas = new HashMap<>();

                    //项目立项需求分析用时
                    //方案评估时间
                    Date schemeCreatedDate = schemeTable.getRows().get(0).getDate("createdtime");

                    //立项发起时间
                    Date initCreatedDate = dataTable.getRows().get(0).getDate("createdtime");
                    datas.put("projectUseNeedDate", getDatePoor(schemeCreatedDate, initCreatedDate));

                    //方案评估用时
                    //合同评审发起时间-方案评估发起时间
                    Date contractCreatedDate = contractTable.getRows().get(0).getDate("createdtime");
                    datas.put("projectUseAssessDate", getDatePoor(contractCreatedDate, schemeCreatedDate));

                    //合同评审用时
                    //验收方案制定申请单发起时间-合同评审发起时间
                    Date acceptanceCreatedDate = acceptanceTable.getRows().get(0).getDate("createdtime");
                    datas.put("projectUseCheckDate", getDatePoor(acceptanceCreatedDate, contractCreatedDate));

                    //验收实施用时
                    //项目总结发起-验收实施发起
                    Date checkUseCreatedDate = implementTable.getRows().get(0).getDate("createdtime");
                    Date projectTotalCreatedDate = totalNoticeTable.getRows().get(0).getDate("createdtime");
                    datas.put("projectUseTotalDate", getDatePoor(projectTotalCreatedDate, checkUseCreatedDate));


                    datas.put("createTime", totalNoticeTable.getRows().get(0).getString("createdtime"));
                    tempProjectSpeed.setDatas(datas);
                    tempProjectSpeeds.add(tempProjectSpeed);
                    //最后一个流程直接跳出
                }
                break;
            }

        }

        return JSONObject.toJSONString(tempProjectSpeeds);
    }


    /***
     * 数据统计
     * @param instanceId
     * @param projectNumber
     * @return
     * @throws Exception
     */
    @RequestMapping(value = "/getNumberAction")
    @ResponseBody
    public String AjaxGetProjectByNumber(@RequestParam("instanceId") String instanceId, @RequestParam("projectNumber") String projectNumber) throws Exception {
        DataTable dataTable = SqlUtil.doQuery("SELECT * FROM i_projectinit ip WHERE ip.projectNumber='" + projectNumber + "'");
        SimpleDateFormat simpleDateFormat = new SimpleDateFormat("yyyy-MM-dd HH:mm:ss");
        DataRow dataRow = dataTable.getRows().get(0);
        TempProject tempProject = new TempProject();

        //总数据list
        HashMap<String, List> totalDatas = new HashMap<>();

        //存储总流程进度以及相关数据
        List<TempProjectSpeed> tempProjectSpeeds = new ArrayList<TempProjectSpeed>();

        //赋值
        if (null != dataRow) {

            //方案评估数据
            while (true) {
                //一个不满足跳出
                DataTable schemeTable = new DataTable();
                schemeTable = SqlUtil.doQuery("SELECT * FROM i_schemeevaluation WHERE projectNumber='" + projectNumber + "'");
                schemeTable.getRows().size();

                if (schemeTable.getRows() != null && schemeTable.getRows().size() > 0) {
                    TempProjectSpeed tempProjectSpeed = new TempProjectSpeed();
                    //进度增加
                    tempProjectSpeed.setNowProgreProjectName("方案评估");
                    tempProjectSpeed.setNowState(true);
                    tempProjectSpeed.setSort(tempProjectSpeed.getSort() + 1);
                    tempProjectSpeeds.add(tempProjectSpeed);

                    //封装数据

                } else {
                    break;
                }

                //合同评审数据
                DataTable contractTable = new DataTable();
                contractTable = SqlUtil.doQuery("SELECT * FROM i_contractreview WHERE projectNumber='" + projectNumber + "'");
                if (contractTable.getRows() != null && contractTable.getRows().size() > 0) {
                    TempProjectSpeed tempProjectSpeed = new TempProjectSpeed();
                    tempProjectSpeed.setNowProgreProjectName("合同评审");
                    tempProjectSpeed.setNowState(true);
                    tempProjectSpeed.setSort(tempProjectSpeed.getSort() + 1);
                    tempProjectSpeeds.add(tempProjectSpeed);
                } else {
                    break;
                }

                //验收方案制定申请单数据
                DataTable acceptanceTable = new DataTable();
                acceptanceTable = SqlUtil.doQuery("SELECT * FROM i_acceptancestandardapp WHERE projectNumber='" + projectNumber + "'");
                if (acceptanceTable.getRows() != null && acceptanceTable.getRows().size() > 0) {
                    TempProjectSpeed tempProjectSpeed = new TempProjectSpeed();
                    tempProjectSpeed.setNowProgreProjectName("验收方案定制");
                    tempProjectSpeed.setNowState(true);
                    tempProjectSpeed.setSort(tempProjectSpeed.getSort() + 1);
                    tempProjectSpeeds.add(tempProjectSpeed);
                } else {
                    break;
                }

                //验收实施
                DataTable implementTable = new DataTable();
                implementTable = SqlUtil.doQuery("SELECT * FROM i_implementationcheck WHERE projectNumber='" + projectNumber + "'");
                if (implementTable.getRows() != null && implementTable.getRows().size() > 0) {
                    TempProjectSpeed tempProjectSpeed = new TempProjectSpeed();
                    tempProjectSpeed.setNowProgreProjectName("验收实施");
                    tempProjectSpeed.setNowState(true);
                    tempProjectSpeed.setSort(tempProjectSpeed.getSort() + 1);
                    tempProjectSpeeds.add(tempProjectSpeed);
                } else {
                    break;
                }

                //项目总结
                DataTable totalNoticeTable = new DataTable();
                totalNoticeTable = SqlUtil.doQuery("SELECT * FROM i_acceptancesummarynotice WHERE projectNumber='" + projectNumber + "'");
                if (totalNoticeTable.getRows() != null && totalNoticeTable.getRows().size() > 0) {
                    TempProjectSpeed tempProjectSpeed = new TempProjectSpeed();
                    tempProjectSpeed.setNowProgreProjectName("项目总结");
                    tempProjectSpeed.setNowState(true);
                    tempProjectSpeed.setSort(tempProjectSpeed.getSort() + 1);
                    tempProjectSpeeds.add(tempProjectSpeed);
                    //最后一个流程直接跳出
                    break;
                }
            }

            //数据封装放入返回JSON LIST中
            totalDatas.put("tempProjectSpeeds", tempProjectSpeeds);

            //发起人
            List<TempProject> tempProjects = new ArrayList<>();
            User user = (User) getEngine().getOrganization().GetUnit(dataRow.getString("createdby"));
            tempProject.setCreatedBy(user.getFullName());
            //流程数据
            tempProject.setProjectName(dataRow.getString("projectname"));
            tempProject.setProjectNumber(dataRow.getString("projectnumber"));
            tempProject.setProjectType(dataRow.getString("projecttype"));
            tempProject.setInBudget(dataRow.getString("inbudget"));
            tempProject.setCreatedTime(simpleDateFormat.parse(dataRow.getString("createdtime")));

            //参与者所有数据封装
            if (!instanceId.isEmpty()) {
                try {
                    InstanceData instanceData = new InstanceData(getEngine(), instanceId, User.AdministratorID);
                    //数据封装
                    HashMap<String, Object> datas = instanceData.getBizObject().getValueTable();

                    //项目组长
                    String[] leaderArray = (String[]) datas.get("projectLeader");
                    if (leaderArray.length != 0) {
                        String tempPerson = "";
                        for (int i = 0; i < leaderArray.length; i++) {
                            tempPerson += getEngine().getOrganization().GetUnit(leaderArray[i])._Name + ",";
                        }
                        tempProject.setProjectLeader(tempPerson);
                    }

                    //技术评审负责人
                    String[] technologyArray = (String[]) datas.get("technologyLeader");
                    if (technologyArray.length != 0) {
                        String tempPerson = "";
                        for (int i = 0; i < technologyArray.length; i++) {
                            tempPerson += getEngine().getOrganization().GetUnit(technologyArray[i])._Name + ",";
                        }
                        tempProject.setTechnologyLeader(tempPerson);
                    }

                    //技术评审组员
                    String[] technouserArray = (String[]) datas.get("technologyMember");
                    if (technouserArray.length != 0) {
                        String tempPerson = "";
                        for (int i = 0; i < technouserArray.length; i++) {
                            tempPerson += getEngine().getOrganization().GetUnit(technouserArray[i])._Name + ",";
                        }
                        tempProject.setTechnologyMember(tempPerson);
                    }

                    //商务评审负责人
                    String[] businessArray = (String[]) datas.get("businessLeader");
                    if (businessArray.length != 0) {
                        String tempPerson = "";
                        for (int i = 0; i < businessArray.length; i++) {
                            tempPerson += getEngine().getOrganization().GetUnit(businessArray[i])._Name + ",";
                        }
                        tempProject.setBusinessLeader(tempPerson);
                    }

                    //商务评审组员
                    String[] businessuserArray = (String[]) datas.get("businessMember");
                    if (businessuserArray.length != 0) {
                        String tempPerson = "";
                        for (int i = 0; i < businessuserArray.length; i++) {
                            tempPerson += getEngine().getOrganization().GetUnit(businessuserArray[i])._Name + ",";
                        }
                        tempProject.setBusinessMember(tempPerson);
                    }

                    //运管委委员
                    String[] operationArray = (String[]) datas.get("operationManager");
                    if (operationArray.length != 0) {
                        String tempPerson = "";
                        for (int i = 0; i < operationArray.length; i++) {
                            tempPerson += getEngine().getOrganization().GetUnit(operationArray[i])._Name + ",";
                        }
                        tempProject.setOperationManager(tempPerson);
                    }


                } catch (Exception e) {
                    System.out.println(e);
                }

            }
            //数据封装放入返回JSON LIST中
            tempProjects.add(tempProject);
            totalDatas.put("tempProject", tempProjects);

        }

        return JSONObject.toJSONString(totalDatas);
    }


    public static String getDatePoor(Date endDate, Date nowDate) {

        long nd = 1000 * 24 * 60 * 60;
        long nh = 1000 * 60 * 60;
        long nm = 1000 * 60;
        // long ns = 1000;
        // 获得两个时间的毫秒时间差异
        long diff = endDate.getTime() - nowDate.getTime();
        // 计算差多少天
        long day = diff / nd;
        // 计算差多少小时
        long hour = diff % nd / nh;
        // 计算差多少分钟
        long min = diff % nd % nh / nm;
        // 计算差多少秒//输出结果
        // long sec = diff % nd % nh % nm / ns;
        return day + "天" + hour + "小时" + min + "分钟";
    }

}
